<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Gitee Callback</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      margin: 0;
      padding: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    .container {
      max-width: 600px;
      margin: 0 auto;
      background: #fff;
      padding: 20px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
      text-align: center;
    }
    h1 {
      color: #333;
    }
    p {
      line-height: 1.6;
    }
  </style>
</head>
<body>
<div class="container">
  <h1>Processing...</h1>
  <p>正在处理您的请求，请稍候。</p>
</div>
<script>
  // 从URL中提取code参数
  const urlParams = new URLSearchParams(window.location.search);
  const code = urlParams.get('code');

  // 发送POST请求到后台服务器
  if (code) {
    fetch('httpTask://localhost:8080/user/login/gitee', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ code: code })
    })
    .then(response => response.json())
    .then(data => {
      console.log(data)
      const message = data.message;
      const nickname = data.data.nickname;
      const msg = message + ' 你好，' + nickname
      // 重定向到home-page.html并携带message信息
      window.location.href = `home-page.html?message=${encodeURIComponent(msg)}`;
    })
    .catch(error => console.error('Error:', error));
  } else {
    console.error('No code found in URL');
  }
</script>
</body>
</html>
